<?php
namespace app\model;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\model\NewsType;

class News extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
 //   protected $append = ['date_time', 'ago_time'];
    //protected $hidden = ['update_time', 'delete_time', 'status'];


    public function searchTypeIdAttr($query, $value, $data)
    {
        if (!empty($value)) {
            $query->where('type_id', 'in', $value);
        }
    }

    public function getTitleAttr($value, $data)
    {
        return getFirstChar($value);
    }


    protected function setTypeIdAttr($value, $data)
    { //当前字段的修改器
        $this->set('type_title', NewsType::where('id', $value)->value('title'));
        return $value;
    }

    /**
     * 设置标题内容
     */

    protected function setDescribeAttr($value, $data)
    {
        if (empty($value)) {
            return trimSpacheEnter($data['content']);
        } else {
            return $value;
        }
    }








}